# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from flask import Blueprint, current_app, request, render_template

try:
    import json
except ImportError:
    import simplejson as json

from ..util import in_text_range, text_required, isObjectId

from ..loginwrapper import login_required, public_network_protection

admin = Blueprint(
    'admin',
    __name__,
    static_folder='../static',
    template_folder='../templates'
)

MODULE_NAME = 'admin'
TEMPLATE_FOLDER = 'admin'

def log(msg, level='debug'):
    getattr(current_app.loger, level)(msg, MODULE_NAME)

def getExcept():
    return current_app.loger.getExcept()

def logExcept():
    ex_msg = getExcept()
    log(ex_msg, 'error')

def template_path(template_file):
    return '{0}/{1}'.format(
        TEMPLATE_FOLDER,
        template_file
    )

@admin.context_processor
def pre_process():
    _upl = current_app.cache.get('users_public_list')
    return {
        'MODULE': MODULE_NAME
    }

@admin.route(r'/', methods=['GET', 'POST'])
def index():
    ''''''
    args = {
        'user': {
            'is_admin': True
        }
    }
    return render_template(template_path('pages/index.html'), **args)

@admin.route(r'/article/', methods=['GET', 'POST'])
def article():
    ''''''
    args = {
        'user': {
            'is_admin': True
        }
    }
    return render_template(template_path('pages/article.html'), **args)